//////////////////////////////////////////////////////////////////////////////////////////////////////////// // // // -------------------- Ebrahim Foulaadvand & Somayyeh Belbasi, 23 June 2009 --------------------------- // // // // The programme "CoupledOscillators" evaluates the temporal evolution of a system of coupled harmonic // // oscillator which are connected to each other by springs. The fix boundary condition is used. // // The second order Runge-Kutta algorithm is used for solving the motion equations. // // // //////////////////////////////////////////////////////////////////////////////////////////////////////////// #include #include #include #include #include #include #include #include #include #include #include using namespace std; main() { randomize(); const N=10, T=5000; // N= number of oscillators, T= number of simulation timesteps. double delt=0.01; // delt=timestep. int i,j,n,s,t; vector< double > m(N+2,0),k(N+3,0),xanal(N+2,0),vanal(N+2,0),x(N+2,0),v(N+2,0),k1x(N+2,0),k2x(N+2,0), k1v(N+2,0),k2v(N+2,0),nu(N+2,0),mu(N+2,0),w(N+2,0); // Arrays "m" and "k" store the oscillators masses and the spring constants. Arrays "x" and "v" store // oscillators positions and velocities. Arrays "xanal" and "vanal" store the analytical values of // positions and velocitis. Arrays "nu","mu" and "w" are used for analytical solutions. Refer to book text // to see their definitions. ofstream file1 ("x analytic5.plt"); // output file for the analytic poistion of particle 5. ofstream file2 ("v analytic5.plt"); // output file for the analytic velocity of particle 5. ofstream file3 ("phasexv analytic5.plt"); // output file for the analytic phase space plot of particle 5. ofstream file4 ("x5.plt"); // output file for the computed poistion of particle 5. ofstream file5 ("v5.plt"); // output file for the computed velocity of particle 5. ofstream file6 ("phasexv5.plt"); // output file for the computed phase space plot of particle 5. for (int i=1;i<=N;i++){ m[i]=1; k[i]=1; } // specification of masses and spring values. k[N+1]=1; // ---------------------------------------- Initial Conditions -------------------------------------------------- xanal[0]=0; vanal[0]=0; xanal[N+1]=0; vanal[N+1]=0; //The fixed boundary condition is modeled by introducing additional fixed particles 0 and N+1. for (int i=1;i<=N;i++){ xanal[i]=0; vanal[i]=0; } x[1]=1; xanal[1]=1; //----------------------------------------- Analytical Solution ------------------------------------------ for (s=1;s<=N;s++) { mu[s]=0; nu[s]=0; w[s]=2*sqrt(k[s]/m[s])*sin( 0.5*s*M_PI/(N+1) ); } for (s=1;s<=N;s++) { for (j=1;j<=N;j++) { mu[s]+=(2/double (N+1))*xanal[j]*sin(j*M_PI*s/(N+1)); nu[s]+=(-2/(w[s]*(N+1)))*vanal[j]*sin(j*M_PI*s/(N+1)); } //cout<<"mu["<